package com.sopra.tecnica.poc.server.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sopra.tecnica.poc.server.dao.CustomerDao;
import com.sopra.tecnica.poc.server.entity.CustomerEntity;

@Service
public class CustomerService {

	@Autowired
	private CustomerDao dao;

	public List<CustomerEntity> findUserCustomers(String code) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("company", "001");
		map.put("userCode", code);
		
		List<CustomerEntity> result = dao.selectWithGenericCriterias(map);
		List<CustomerEntity> resultWithLatLong = new ArrayList<CustomerEntity>();
		for (CustomerEntity customer : result) {
			int customerCode = Integer.parseInt(customer.getCode());
			boolean shouldAdd = false;
			switch (customerCode) {
			case 943142:
				customer.setLatitude(46.068294f);
				customer.setLongitude(6.570339f);
				shouldAdd = true;
				break;
			case 941464:
				customer.setLatitude(45.93684f);
				customer.setLongitude(6.090281f);
				shouldAdd = true;
				break;
			case 943567:
				customer.setLatitude(46.060541f);
				customer.setLongitude(6.579441f);
				shouldAdd = true;
				break;
			case 943366:
				customer.setLatitude(45.905936f);
				customer.setLongitude(6.430221f);
				shouldAdd = true;
				break;
			case 940421:
				customer.setLatitude(45.905976f);
				customer.setLongitude(6.430421f);
				shouldAdd = true;
				break;
			}
			
			if (shouldAdd) {
				resultWithLatLong.add(customer);
			}
		}
		
		return resultWithLatLong;
	}

	public List<Map<String, Object>> findOrderCustomer(int orderNum) {
		return dao.findOrderCustomer(orderNum);
	}
}
